from selenium.webdriver.common.by import By
from Zk_2211A.Zk_3.Base.Base import Base
import time

class Page(Base):

    # 封装页面元素
    # 请登录
    login_loc = (By.CLASS_NAME, 'headerLogin')
    # 账号输入框
    user_input = (By.ID, 'userName')
    # 密码输入框
    pwd_input = (By.ID, 'password')
    # 登录按钮
    login_button = (By.XPATH, '//*[@id="save"]')
    # 弹窗确定
    alert = (By.XPATH, '/html/body/div/div[4]/div[2]/div[2]/a')
    # 我的酒仙
    my_jiuxian = (By.XPATH, '/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a')
    # 提示弹窗
    alert_ts = (By.CLASS_NAME, 'uGuideClose')
    # 收货地址
    address = (By.XPATH, '/html/body/div[4]/div[1]/div[2]/div[4]/a[3]/span')
    # 收货人
    shr = (By.NAME, 'consignee')
    # 地区
    province = (By.CSS_SELECTOR, '#province')
    city = (By.NAME, 'city')
    district = (By.NAME, 'district')
    # 详细地址
    xx_address = (By.XPATH, '//*[@id="address"]')
    # 邮政编码
    zipcode = (By.ID, 'zipcode')
    # 手机号
    iphone = (By.ID, 'iphone')
    # 提交
    tj_button = (By.XPATH, '//*[@id="save"]')
    # 确定
    qd_button = (By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b')
    # 删除
    delete_text = (By.CLASS_NAME, 'controlRemove')
    # 确定
    qd_text = (By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b')
    # 确定删除
    qd_delete = (By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b')

    # 调用base中的方法，封装页面元素
    # 封装点击请登录方法
    def please_login(self):
        self.click(self.login_loc)
    # 封装输入账号方法
    def send_user(self):
        self.send_keys(self.user_input, '15523615751')
    # 封装输入密码方法
    def send_pwd(self):
        self.send_keys(self.pwd_input, 'lj070130.')
    # 封装点击登录按钮方法
    def click_login(self):
        self.click(self.login_button)
    # 封装点击弹窗确定方法
    def click_alert(self):
        self.click(self.alert)
    # 封装点击我的酒仙的方法
    def click_my(self):
        self.click(self.my_jiuxian)
        # 调用窗口切换的方法
        self.new_window()
    # 封装关闭提示弹窗的方法
    def close_alert(self):
        self.click(self.alert_ts)
    # 封装点击收货地址的方法
    def click_address(self):
        self.click(self.address)
    # 封装输入收货人的方法
    def send_shr(self):
        self.send_keys(self.shr, '小六')
    # 封装选择地区的方法
    def address_select(self):
        self.select(self.province, '2')
        self.select(self.city, '52')
        self.select(self.district, '512')
    # 封装输入详细地址的方法
    def send_xxaddress(self):
        self.send_keys(self.xx_address, '水厂路小区')
    # 封装输入邮政编码的方法
    def send_zipcode(self):
        self.send_keys(self.zipcode, '100160')
    # 封装输入手机号的方法
    def send_iphone(self):
        self.send_keys(self.iphone, '15523615751')
    # 封装点击提交的方法
    def click_tj(self):
        self.click(self.tj_button)
    # 封装点击确定按钮的方法
    def cilck_qd(self):
        self.click(self.qd_button)
    # 封装点击删除按钮的方法
    def click_delete(self):
        self.click(self.delete_text)
    # 封装点击确定按钮的方法
    def click_qd2(self):
        self.click(self.qd_text)
    # 封装点击确定按钮的方法
    def click_qd_delete(self):
        self.click(self.qd_delete)
    # 鼠标释放
    def sb_release(self):
        self.release(self.my_jiuxian)

    # 封装登录业务
    def login_jiuxian(self):
        # 打开酒仙网
        self.open_url('https://www.jiuxian.com/')
        # 鼠标左键点击请登录
        self.please_login()
        # 输入账号
        self.send_user()
        # 输入密码
        self.send_pwd()
        time.sleep(15)
        # 点击登录按钮
        self.click_login()
        # 点击弹窗确定
        self.click_alert()

    # 封装添加地址业务
    def add_address(self):
        # 调用登录业务
        self.login_jiuxian()
        # 点击我的酒仙
        self.click_my()
        # 关闭弹窗
        self.close_alert()
        # 滚动
        self.scrollTo(600)
        # 点击收货地址
        self.click_address()
        # 输入收货人
        self.send_shr()
        # 选择地区
        self.address_select()
        # 输入详细地址
        self.send_xxaddress()
        # 输入邮政编码
        self.send_zipcode()
        # 输入手机号
        self.send_iphone()
        # 点击提交
        self.click_tj()
        # 点击确定
        self.cilck_qd()

    # 封装删除地址业务
    def delete_address(self):
        # 调用登录业务
        self.login_jiuxian()
        # 点击我的酒仙
        self.click_my()
        # 关闭弹窗
        self.close_alert()
        # 滚动
        self.scrollTo(600)
        # 点击收货地址
        self.click_address()
        # 点击删除
        self.click_delete()
        # 点击确定
        self.click_qd2()
        # 点击确定
        self.click_qd_delete()